The .create() method does not support writable nested fields by default. Write an explicit .create() method for serializer room_api.serializers.roomSerializer, or set read_only=True on nested serializer fields.

52

class CoreInformation(generics.ListCreateAPIView):
    queryset = models.CoreInformation.objects.all()
    serializer_class = CustomCoreInfoSerializer

    def create(self, request, *args, **kwargs):
        serializer = self.get_serializer(data=request.data)
        serializer.is_valid(raise_exception=True)
        instance = self.perform_create(serializer)
        serializer = self.get_serializer(instance=instance)
        return Response(serializer.data, status=status.HTTP_201_CREATED)

    def perform_create(self, serializer):
        return serializer.create(validated_data=serializer.validated_data)

Comments

Submit
0 Comments